package com.fyzk.random;

import com.fyzk.activity.lottery.gaopin.K3Activity;
import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.betcode.AppLotteryCodeListManager;
import com.fyzk.betcode.BetLotteryInfo;
import com.fyzk.betcode.CodeFactory;
import com.fyzk.utils.LotteryIDUtils;
import com.fyzk.utils.RandomUtil;

import java.util.ArrayList;
import java.util.List;

import static com.fyzk.activity.lottery.gaopin.K3Activity.K3_LOTTERY_ERBUTONGHAO_DAN_ID_INT;
import static com.fyzk.activity.lottery.gaopin.K3Activity.K3_LOTTERY_ERBUTONGHAO_ZU_ID_INT;
import static com.fyzk.activity.lottery.gaopin.K3Activity.K3_LOTTERY_ERTONGHAO_DAN_ID_INT;
import static com.fyzk.activity.lottery.gaopin.K3Activity.K3_LOTTERY_SANBUTONGHAO_DAN_ID_INT;
import static com.fyzk.activity.lottery.gaopin.K3Activity.K3_LOTTERY_SANTONGHAO_ID_INT;
import static com.fyzk.activity.lottery.gaopin.K3Activity.K3_LOTTERY_SUMZHI_ID_INT;


public class K3Random extends RandomBase {

    @Override
    public int[] randomDanHang(int count) {
        // TODO Auto-generated method stub
        int[] arr = RandomUtil.randomNoRepeat(count, 0, 11);
        return arr;

    }

    @Override
    public int[] randomDuoHang(int count, int start, int end) {
        // TODO Auto-generated method stub
        int[] arr = RandomUtil.randomNoRepeat(count, start, end);
        return arr;
    }

    @Override
    public void randomYiZhu(BetLotteryInfo infor) {
        // TODO Auto-generated method stub
        int wanFaId = infor.wcodeID;
        int popupID = infor.popupID;
        int zhuShu = 1;
        List<List<BallInfo>> arr_infos = infor.arr_infos;
        arr_infos = initList2(arr_infos);
        List<List<BallInfo>> ballInfos = new ArrayList<>();

        if (wanFaId == K3_LOTTERY_SUMZHI_ID_INT) {  // 和值
            wanFaId = K3Activity.K3_LOTTERY_SUMZHI_ID_INT;
            ballInfos.add(arr_infos.get(0));
            randomHe(ballInfos, 0, 16);
            popupID = 0;
        } else if (wanFaId == K3_LOTTERY_SANTONGHAO_ID_INT || wanFaId == K3Activity
                .K3_LOTTERY_SANTONGHAO_TONG_ID_INT) {   // 三同号单式、复式
            wanFaId = K3_LOTTERY_SANTONGHAO_ID_INT;
            ballInfos.add(arr_infos.get(1));
            randomHe(ballInfos, 0, 6);
            popupID = 1;
        } else if (wanFaId == K3_LOTTERY_ERTONGHAO_DAN_ID_INT || wanFaId == K3Activity
                .K3_LOTTERY_ERTONGHAO_FU_ID_INT) {  // 二同号单式、复式
            wanFaId = K3_LOTTERY_ERTONGHAO_DAN_ID_INT;
            ballInfos.add(arr_infos.get(2));
            ballInfos.add(arr_infos.get(3));
            randomHe(ballInfos, 0, 6);
            popupID = 2;
        } else if (wanFaId == K3_LOTTERY_SANBUTONGHAO_DAN_ID_INT || wanFaId == K3Activity
                .K3_LOTTERY_SANBUTONGHAO_ZU_ID_INT || wanFaId == K3Activity
                .K3_LOTTERY_SANLIANHAO_TONG_ID_INT || wanFaId == K3Activity.K3_LOTTERY_SANBUTONGHAO_TOWED_ID_INT) {
            wanFaId = K3_LOTTERY_SANBUTONGHAO_DAN_ID_INT;
            ballInfos.add(arr_infos.get(5));
            random2(ballInfos, 3, 0, 6);
            popupID = 3;
        } else if (wanFaId == K3_LOTTERY_ERBUTONGHAO_DAN_ID_INT || wanFaId ==
                K3_LOTTERY_ERBUTONGHAO_ZU_ID_INT || wanFaId == K3Activity.K3_LOTTERY_ERBUTONGHAO_TOWED_ID_INT) {
            wanFaId = K3Activity.K3_LOTTERY_ERBUTONGHAO_DAN_ID_INT;
            ballInfos.add(arr_infos.get(6));
            random2(ballInfos, 2, 0, 6);
            popupID = 4;
        }

        String Zhuma = CodeFactory.getCode(wanFaId).betCode(arr_infos);
        String showZhuMa = CodeFactory.getCode(wanFaId).formatHtmlCode2(Zhuma);
        AppLotteryCodeListManager.getInstance().

                AddLotteryInfo(wanFaId,
                        Zhuma, showZhuMa, zhuShu, arr_infos, popupID);

    }

    /**
     *
     * @param ballInfos
     * @param start
     * @param end
     */
    private void randomHe(List<List<BallInfo>> ballInfos, int start, int end) {
        int arr[] = randomDuoHang(ballInfos.size(), start, end);
        if (arr.length != ballInfos.size()) {
            return;
        }
        for (int i = 0; i < arr.length; i++) {
            ballInfos.get(i).get(arr[i]).setSelected(true);
        }
    }

    /**
     * 机选号(1)
     *
     * @param num
     */
    private void random2(List<List<BallInfo>> ballInfos, int num, int start, int end) {
        int arr[] = RandomFactory.getRandom(
                LotteryIDUtils.NXK3_LOTTERY_ID_INT).randomDuoHang(num, start, end);
        for (int i = 0; i < arr.length; i++) {
            ballInfos.get(0).get(arr[i]).setSelected(true);
        }
    }

}
